<template>
  <div class="app-container">
    <div class="container-bg">
      <div class="filter-container">
        <el-input v-model="listQuery.name" placeholder="姓名" style="width: 120px" class="filter-item"/>
        <el-date-picker style="width: 380px" class="filter-item m-margin-l10" v-model="dateTime" type="datetimerange"
          :editable="false" range-separator="~" value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期" :picker-options="pickerOptions"
          :default-time="['00:00:00', '23:59:59']">
        </el-date-picker>
        <el-select  style="width: 200px" v-model="listQuery.query_type" placeholder="请选择特征值状态"
                   class="filter-item m-margin-l10">
          <el-option v-for="(v, i) in eigenvalueStatus" :key="v.value" :label="v.name" :value="v.value"/>
        </el-select>
        <el-button
        class="filter-item m-margin-l10"
        type="primary"
        icon="el-icon-search"
        @click="onSearch"
        >查询
        </el-button>
        <el-button class="filter-item m-margin-l10" type="warning" icon="el-icon-refresh" @click="onReset">重置
        </el-button>
        <div style="float: right; display: flex">
          <el-button class="m-margin-l10" icon="el-icon-edit" type="primary" @click="addDevice('2')" v-if="false">设备注册
          </el-button>
          <el-button class="m-margin-l10" icon="el-icon-edit" type="primary" @click="addCommunityPerson('2')" v-if="false">批量注册
          </el-button>
          <el-button class="m-margin-l10" icon="el-icon-edit" type="primary" @click="addCommunityPerson(1)">单人注册
          </el-button>
        </div>

        <div style="float: right; display: flex">
          <el-button icon="el-icon-delete" class="filter-item" type="danger" plain
                      @click="doDeleteCommunityPersonSelect">批量删除
          </el-button>
          <el-button icon="el-icon-delete" class="filter-item" type="danger"
                      @click="doDeleteCommunityPersonAll">全部清除
          </el-button>
          <el-button class="filter-item" style="margin-left: 10px" type="success" @click="doDownloadFile"
                      v-if="false"
                      :disabled="personData.total == 0">导出
          </el-button>
        </div>
      </div>

      <div style="width: 100%">
        <el-row>
          <el-col :span="6" align="center">
            <el-tag>
              当前数量<br/>
              <div style="white-space: nowrap">
                人员数量：{{
                  faceCount.face_count ? faceCount.face_count : "0"
                }}
                / 最大人员个数：{{
                  faceCount.max_face_count ? faceCount.max_face_count : "0"
                }}
              </div>
            </el-tag>
          </el-col>
          <el-col :span="6" align="center">
            <el-tag>
              人脸特征值数量<br/>
              <div style="white-space: nowrap">
                 成功个数：{{
                  faceCount.feature_face_sucess_count ? faceCount.feature_face_sucess_count : "0"
                }}
                / 失败个数：{{
                  faceCount.feature_face_fail_count ? faceCount.feature_face_fail_count : "0"
                }}
                / 未生成：{{
                  faceCount.feature_to_be_generated ? faceCount.feature_to_be_generated : "0"
                }}
              </div>
            </el-tag>
          </el-col>

          <el-col :span="6" align="center" v-if="false">
            <el-tag>
              图片失败统计<br/>
              <div style="white-space: nowrap">
                下载失败：{{
                  faceCount.iamge_downfail_count ? faceCount.iamge_downfail_count : "0"
                }}
                / 图片异常：{{
                  faceCount.iamge_dataerror_count ? faceCount.iamge_dataerror_count : "0"
                }}
              </div>
            </el-tag>
          </el-col>
          <el-col :span="6" align="center" v-if="false">
            <el-tag>
              同步时间<br/>
              <div style="white-space: nowrap">
                人员：{{
                  faceCount.user_insert_time ? faceCount.user_insert_time : "0"
                }}
                / 特征值：{{
                  faceCount.feature_insert_time ? faceCount.feature_insert_time : "0"
                }}
              </div>
            </el-tag>
          </el-col>
        </el-row>
      </div>

      <el-table :data="personData.list" border fit highlight-current-row
        v-loading="loading"
        element-loading-text="正在加载数据，请耐心等待"
        :max-height="600"
        :min-height="500"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="40"></el-table-column>
        <el-table-column align="center" label="人员ID" show-overflow-tooltip width="180">
          <template slot-scope="scope">{{ scope.row.personId }}</template>
        </el-table-column>
        <el-table-column align="center" label="工号" show-overflow-tooltip width="130">
          <template slot-scope="scope">{{ scope.row.personNum }}</template>
        </el-table-column>
        <el-table-column align="center" label="姓名" show-overflow-tooltip width="130">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column align="center" label="类型" v-if="false">
          <template slot-scope="scope">{{ scope.row.sType | sType }}</template>
        </el-table-column>
        <el-table-column align="center" class-name="status-col" label="生效时间" prop="sRegistrationTime">
          <template slot-scope="scope">
            <span>{{ scope.row.effectiveStartTime }} </span>
            <span style="margin: 0 10px">~</span>
            <span>{{ scope.row.validEndTime }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="人脸特征值状态" width="180">
          <template slot-scope="scope">{{ scope.row.feature_state | feature_state }}</template>
        </el-table-column>
        <el-table-column align="center" class-name="status-col" label="操作" width="240">
          <template slot-scope="{ row, $index }">
            <el-row>
              <el-button size="mini" class="light_blue_btn" @click="editCommunityPerson(row, $index)">修改
              </el-button>
              <el-button type="success" size="mini" @click="goDetails(row, $index)">查看
              </el-button>
              <el-popconfirm cancel-button-text="不用了" class="m-margin-l10" confirm-button-text="好的"
                             icon="el-icon-info"
                             icon-color="red" title="您确定删除当前人员吗？" @confirm="doDeleteCommunityPerson">
                <el-button slot="reference" size="mini" class="light_red_btn" @click="deleteCommunityPerson(row)">删除
                </el-button>
              </el-popconfirm>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <pagination :limit.sync="listQuery.limit" :page.sync="listQuery.page" :total="personData.total"
        :page-sizes="[20, 100, 500]" @pagination="changePage"/>
      </div>
    <!-- 单个添加人员 -->
    <el-dialog :visible.sync="dialogFormVisible" v-if="dialogFormVisible" width="740px" :title="drTitle" class="frame"
               :close-on-click-modal="false" @close="onClose">
      <el-form class="el-form-box" ref="dataForm" :model="form" :rules="rules" label-position="left" label-width="120px"
               style="margin: 0 50px">
        <el-form-item label="人员ID" prop="personId">
          <el-input v-model.trim="form.personId" placeholder="请输入人员ID" v-bind:disable="disID" :disabled="drTitle=='单人修改'"/>
        </el-form-item>
        <el-form-item label="工号" prop="personNum">
          <el-input v-model.trim="form.personNum" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="特征类型" prop="identityType">
          <el-select v-model="form.identityType" placeholder="请选择" type="number" clearable
          @change="selectChange">
            <el-option
              v-for="item in identityType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生效时间" prop="effectivedate">
          <el-date-picker @input="$forceUpdate()" v-model="form.effectivedate" type="datetimerange" range-separator="-"
                          start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                          :default-time="['00:00:00', '23:59:59']"/>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model.trim="form.name" placeholder="请输入姓名" maxlength="20"/>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择" type="number"
          @change="selectChange">
            <el-option
              v-for="item in genderOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="通行卡" prop="thirdpartyId" v-if="this.form.identityType == 3 && this.form.infoType">
          <el-input v-model.trim="form.thirdpartyId" placeholder="请输入通行卡" maxlength="20"/>
        </el-form-item>
        <div style="width: 300px;margin-top: 10px" v-if="this.form.method == 1">
          <el-upload
            :file-list="imageList"
            :auto-upload="false"
            ref="uploadImg"
            action=""
            accept=".png,.jpg,.jpeg"
            :count='1'
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            :on-change="getFile"
          >
            <el-button type="primary" size="small"><i class="el-icon-plus"></i>上传图片</el-button>
          </el-upload>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="saveCommunityPersonInfo()">提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getBase64,
  getFacePersonsListApi,
  personsUploadApi,
  addFacePersonsApi,
  editFacePersonsApi,
  delFacePersonsApi,
  getFacePersonsListNamesApi,
  getLastFaceApi,
  getFaceWaitingApi,
  getFaceCheckIdsApi,
  getFacePersonsApi,
  faceListExportUrlApi,
  clearAllUserApi,
  getErrorList,
  doDelError,
  doDelErrorMultiple,
  clearAllErrors,
  getPersonTemplate,
  uploadPerson,
  uploadImage,
  getErrorList2,
  doDelError2,
  doDelErrorMultiple2,
  clearAllErrors2,
  predictSubmitStatusApi,
  getFaceCountApi,
  controlRecordExportUrlApi,
} from "@/api/community/communityPerson";
import axios from 'axios';
import { getToken } from "@/utils/auth";
import $ from 'jquery';
import {
  getPersonList,
  addPerson,
  editEventIdentity,
  // getEventIdentity,
  fileUpload,
  fileUploadApi,
  delUploadPicApi,
} from "@/api/community/person";


const rules = {
  personId: [
    {
      trigger: ["blur"],
      required: true,
      message: "人员ID不能为空",
    },
    {
      pattern:
        /^[A-Za-z0-9_]{1,32}$/,
      message: "1-32位,包含数字、大小写字母和_",
      trigger: "blur",
    },
  ],
  personNum: [
    {
      trigger: ["blur"],
      required: true,
      message: "工号不能为空",
    },
    {
      pattern:
        /^[A-Za-z0-9]{1,32}$/,
      message: "1-32位,包含数字、大小写字母",
      trigger: "blur",
    },
  ],
  identityType: [
    {
      trigger: ["change"],
      required: true,
      message: "特征类型不能为空",
    },
  ],
  name: [
    {
      trigger: ["blur", "change"],
      required: true,
      message: "姓名不能为空",
      // pattern: cnReg,
    },
  ],
  gender: [
    {
      trigger: ["blur", "change"],
      required: true,
      message: "性别不能为空",
      // pattern: cnReg,
    },
  ],
  thirdpartyId: [
    {
      trigger: ["blur", "change"],
      required: true,
      message: "不能为空",
      // pattern: cnReg,
    },
  ],
  sTelephoneNumber: [
    {
      required: false,
      message: "手机号码不能为空",
      trigger: ["blur"],
    },
    {
      pattern: /^1[0-9]\d{9}$/,
      message: "请输入正确的号码",
      trigger: ["blur"],
    },
  ],
  sCertificateNumber: [
    {
      trigger: ["blur", "change"],
      required: false,
      message: "请填写身份证信息",
    },
    {
      pattern: /(^\d{18}$)|(^\d{15}$)/,
      message: "请输入正确的身份证",
      trigger: ["blur", "change"],
    },
  ],
  effectivedate: [
    {
      trigger: "blur",
      required: true,
      message: "请选择生效日期",
    },
  ],
  iAccessCardNumber: [
    {
      trigger: "blur",
      required: true,
      message: "请输入门禁卡号",
    },
  ],
};

let rangDate = [
  new Date(),
  new Date(
    new Date().getFullYear() + 3,
    new Date().getMonth(),
    new Date().getDate(),
    23,
    59,
    59
  ),
];

export default {
  data() {
    return {
      listQuery: {
        "name": "",
        "begin_time": 1700610911,
        "end_time": 1700619911,
        "query_type": 0,
        "offset":0,
        "count":20
      },
      personData: {list: [], total: 0},
      genderOptions: [
        {label: "未知", value: 0},
        {label: "男", value: 1},
        {label: "女", value: 2},
      ],
      identityType: [
        {
          value: '1',
          label: '人脸'
        }, {
          value: '2',
          label: '掌静脉',
          disabled: true
        }, {
          value: '3',
          label: '通行卡',
          disabled: true
        }, {
          value: '4',
          label: '密码',
          disabled: true
        }, {
          value: '5',
          label: '掌纹',
          disabled: true
        }, {
          value: '6',
          label: '虹膜',
          disabled: true
        }, {
          value: '7',
          label: '指纹',
          disabled: true
        }, {
          value: '8',
          label: '指静脉',
          disabled: true
        }
      ],
      eigenvalueStatus: [
        {name: "全部", value: 0},
        {name: "人脸成功", value: 1},
        {name: "人脸失败", value: 2},
        {name: "人脸待生成", value: 3},
        {name: "全部错误", value: 7},
        {name: "黑名单", value: 8},
      ],
      rules,
      dateTime: [],
      faceCount: {},
      facePath: '',
      dialogFormVisible: false,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      form: {
        effectiveStartTime: "2023-02-28 09:11:26",
        name: "",
        validEndTime: "2026-02-28 23:59:59",
        query_type: 0,
        effectivedate: ["2023-02-28 09:11:26", "2025-02-28 23:59:59"],
      },
    };
  },
  filters: {
    query_type(val) {
      switch (val) {
        case 0:
          return "全部";
        case 1:
          return "人脸成功";
        case 2:
          return "人脸失败";
        case 3:
          return "人脸待生成";
        case 4:
          return "虹膜成功";
        case 5:
          return "虹膜失败";
        case 6:
          return "虹膜待生成";
      }
    },
    feature_state(val) {
      switch (val) {
        case -1:
          return "生成失败";
        case 0:
          return "无人脸";
        case 1:
          return "已经生成";
        case 2:
          return "未生成";
        case 100:
          return "下载失败";
        case 101:
          return "图片异常";
      }
    },
    ir_feature_state(val) {
      switch (val) {
        case -1:
          return "生成失败";
        case 0:
          return "无虹膜";
        case 1:
          return "已经生成";
        case 2:
          return "未生成";
        case 100:
          return "下载失败";
        case 101:
          return "图片异常";
      }
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    selectChange() {
      this.$forceUpdate();
    },
    changePage(val) {
      console.log(335, val);
      let [page, count] = [val.page, val.limit];
      this.listQuery.page = page;
      this.listQuery.count = count;
      this.listQuery.offset = (page-1)*count;
      this.doGetCommunityPersons();
    },
    timeShift(val) {
      console.log(527, val);
      var oHour = val < 3600 ? 0 : Math.floor(val/3600);
      var oMin = Math.floor((val % 3600) / 60);
      var oSec = Math.floor(val % 60);
      oMin = oMin < 10 ? '0' + oMin : oMin;
      oSec = oSec < 10 ? '0' + oSec : oSec;
      console.log(534, oHour + ':' + oMin + ':' + oSec);
      return oHour + ':' + oMin + ':' + oSec;
    },
    doGetCommunityPersons() {
      this.loading = true;

      this.personData.list = [];
      if (!this.dateTime) this.dateTime = [];
      this.listQuery.begin_time = this.$moment(this?.dateTime[0]).unix().toString() ?? this.$moment("1970-01-01 00:00:00").unix().toString();
      this.listQuery.end_time =
      this.$moment(this?.dateTime[1]).unix().toString() ??
        this.$moment(this.$moment().endOf("day").unix() * 1000);

      if (this.dateTime.length === 0) {
        this.listQuery.begin_time = "";
        this.listQuery.end_time = "";
      }
      console.log(72, this.listQuery);
      // console.log(73, JSON.parse(sessionStorage.getItem('tmpListQuery')));
      if (sessionStorage.getItem('tmpListQuery')) {
        this.listQuery = JSON.parse(sessionStorage.getItem('tmpListQuery'));
        console.log(74, this.listQuery);
        if (this.listQuery.begin_time*1 > 0) {
          this.dateTime.push(this.$moment(this.listQuery.begin_time * 1000).format("YYYY-MM-DD HH:mm:ss"));
          this.dateTime.push(this.$moment(this.listQuery.end_time * 1000).format("YYYY-MM-DD HH:mm:ss"));
        }
        setTimeout(() => {
          sessionStorage.removeItem('tmpListQuery');
        }, 100);
      }
      axios.post(
        "http://"+location.hostname+"/mdb/query",
        // "http://"+location.hostname + ":91/dev-api" + "/mdb/query",
        this.listQuery,
        ).then(res=>{
          console.log(408,res);
          this.faceCount.face_count = res.data.face_count;
          this.faceCount.max_face_count = res.data.max_face_count;
          this.faceCount.feature_face_fail_count = res.data.feature_face_fail_count;
          this.faceCount.feature_face_sucess_count = res.data.feature_face_sucess_count;
          this.faceCount.feature_isir_fail_count = res.data.feature_isir_fail_count;
          this.faceCount.feature_isir_sucess_count = res.data.feature_isir_sucess_count;
          this.faceCount.iamge_downfail_count = res.data.iamge_downfail_count;
          this.faceCount.iamge_dataerror_count = res.data.iamge_dataerror_count;
          this.faceCount.user_insert_time = this.timeShift(res.data.user_insert_time);
          this.faceCount.feature_insert_time = this.timeShift(res.data.feature_insert_time);
          this.faceCount.feature_to_be_generated = res.data.feature_to_be_generated;
          if (res.data.total == 0 || res.data.data === null) {
            this.personData.list = [];
            this.personData.total = 0;
            this.loading = false;
          } else {
            if (res.data.data.length > 0) {
              res.data.data.forEach((item) => {
                item.effectiveStartTime = this.$moment(item.start_time * 1000).format("YYYY-MM-DD HH:mm:ss");
                item.validEndTime = this.$moment(item.end_time * 1000).format("YYYY-MM-DD HH:mm:ss");
              });
              this.personData.list = res.data.data;
              this.personData.total = res.data.total;
              this.loading = false;
              this.$nextTick(() => {
                // 请求上一页
                if (this.listQuery.page != 1 && this.personData.list.length == 0) {
                  this.changePage({page: this.listQuery.page - 1});
                }
              });
            }
          }
          console.log(409,this.personData);
        },err =>{
          console.log(err)
      })
      .catch(error =>{
          console.log(error);
      })
    },
    onSearch() {
      this.listQuery.page = 1;
      this.listQuery.count = 20;
      this.listQuery.offset = 0;
      this.doGetCommunityPersons();
    },
    onReset() {
      this.personData.list = [];
      this.personData.total = 0;
      this.listQuery = {
        begin_time: "",
        end_time: "",
        name: "",
        count: 20,
        limit: 20,
        offset: 0,
        page: 1,
        query_type: 0,
      };
      this.dateTime = [];
      this.doGetCommunityPersons();
    },
    submitForm() {
        this.$refs.elForm.validate((valid) => {
        if (valid) {
            let params = { ...this.form };
            delete params.syncTime;

            // let p1 = new Promise((resolve, reject) => {
            //   params.iRefreshTime = +params.iRefreshTime;
            //   editSystemNetworkApi(params)
            //     .then((res) => {
            //       // resolve(res);
            //       this.$message.success("保存成功");
            //     })
            //     .catch((err) => {
            //       // resolve(err);
            //       this.$message.error("保存失败");
            //     });
            // });
        }
        });
    },
    // 详情页
    goDetails(val) {
      console.log(588, val);
      sessionStorage.setItem('tmpListQuery', JSON.stringify(this.listQuery));
      console.log(600, sessionStorage.getItem('tmpListQuery'));
      let formObj = {
        name:this.listQuery.name,
        dateTime:this.dateTime,
        loadCompleted:this.listQuery.query_type,
        count:this.listQuery.count,
        page:this.listQuery.page
      }
      this.$store.commit('setYhglForm',formObj);
      this.$router.push({
        name: "person-details",
        query: {id: val.personId, name: val.name, gender: val.gender},
      });
    },
    handleSelectionChange(value) {
      console.log("value", value);
      this.selectList = [];
      for (let i = 0; i < value.length; i++) {
        this.selectList.push({id: value[i].personId});
      }
    },
    // 删除
    deleteCommunityPerson(_row) {
      console.log("rw", _row);
      this.selectList = [{id: _row.personId}];
    },
    doDeleteCommunityPerson() {
      if (!this.selectList || this.selectList.length === 0) {
        this.$message.warning("请选择删除人员");
        return;
      }
      for (let i = 0; i < this.selectList.length; i++) {
        console.log(this.selectList);
        this.loading = true;
        delFacePersonsApi({personId: this.selectList[i].id})
          .then((res) => {
            if (i == this.selectList.length - 1) {
              this.$message.success("删除成功");
              this.doGetCommunityPersons();
              this.selectList = [];
            }
          })
          .catch((err) => {
            if (i == this.selectList.length - 1) {
              this.$message.success("删除成功");
              this.doGetCommunityPersons();
              this.selectList = [];
            }
          });
      }
    },
    doDeleteCommunityPersonSelect() {
      if (!this.selectList || this.selectList.length === 0) {
        this.$message.warning("请选择删除人员");
        return;
      }
      const h = this.$createElement;
      this.$msgbox({
        title: "提示",
        message: h("p", null, [
          h("span", null, `此操作将永久删除所选`),
          h("i", {style: "color: #f00"}, this.selectList.length),
          h("span", null, "个人员, 是否继续?"),
        ]),
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        beforeClose: (action, instance, done) => {
          if (action === "confirm") {
            done();
          } else {
            done();
          }
        },
      }).then((action) => {
        console.log("this.selectList", this.selectList);
        // console.log(action);
        for (let i = 0; i < this.selectList.length; i++) {
          delFacePersonsApi({personId: this.selectList[i].id})
            .then((res) => {
              if (i == this.selectList.length - 1) {
                this.$message.success("删除成功");
                this.doGetCommunityPersons();
                this.selectList = [];
              }
            })
            .catch((err) => {
              if (i == this.selectList.length - 1) {
                this.$message.success("删除成功");
                this.doGetCommunityPersons();
                this.selectList = [];
              }
            });
        }
      });
      return false;

      this.$confirm(
        `此操作将永久删除所选${this.selectList.length}个人员, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          for (let i = 0; i < this.selectList.length; i++) {
            delFacePersonsApi(this.selectList[i].id)
              .then((res) => {
                if (i == this.selectList.length - 1) {
                  this.$message.success("删除成功");
                  this.doGetCommunityPersons();
                  this.selectList = [];
                }
              })
              .catch((err) => {
                if (i == this.selectList.length - 1) {
                  this.$message.success("删除成功");
                  this.doGetCommunityPersons();
                  this.selectList = [];
                }
              });
          }
        })
        .catch(() => {
          // this.$message.info("已取消删除");
        });
    },
    doDeleteCommunityPersonAll() {
      this.$confirm("此操作将永久删除所有人员, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          clearAllUserApi().then((res) => {
            // console.log(res);
            this.$message.success("删除成功");
            var that = this;
            setTimeout(() => {
              that.doGetCommunityPersons();
            }, 1000);
          });
        })
        .catch(() => {
          // this.$message.info("已取消删除");
        });
    },
    // 添加人脸
    addCommunityPerson(msg) {
      if (msg == 1) {
        this.drTitle='单人新增';
        this.form = {};
        this.form.effectivedate = rangDate;
        this.form.method = 1;
        this.form.identityType = '1';
        this.form.gender = 1;
        this.infoType = true;
        this.dialogFormVisible = true;
        return false;
      }
      this.dialogFormGroup = true;
      this.isShowUpload = true
      this.isShowUpload2 = true
      //判断是否能够批量上传
      this.predictSubmitStatus();
    },
    reset() {
      this.resetForm("form");
      this.form = {
        effectiveStartTime: "2023-02-28 09:11:26",
        name: "",
        validEndTime: "2026-02-28 23:59:59",
        loadCompleted: "",
        effectivedate: rangDate,
      };
      this.fileForm = undefined;
    },
    // 修改
    editCommunityPerson(_row, _index) {
      this.drTitle='单人修改'
      this.reset();
      this.singleLoading = false;
      this.infoType = false;
      this.disID = true;
      this.form.method = 2;
      console.log(770, this.form);
      this.ipersonId = _row.personId;
      this.form = this.$fn.deepCopy(_row);
      this.form.effectivedate = [_row.effectiveStartTime, _row.validEndTime];
      this.form.identityType = '人脸';
      this.dialogFormVisible = true;
      // $('.frame .el-dialog__title').text('单人修改');
    },
    // 提交单个的
    saveCommunityPersonInfo() {
      console.log(811, this.form);
      var self = this;
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          self.form.identityData = this.facePath.length > 0 ? self.facePath : '';
          if (!self.form.identityData && self.form.method == 1) {
            this.$message.error('图片必须上传');
            return false;
          }
          self.singleLoading = true;
          // self.form.effectiveStartTime = parseTime(self.form.effectivedate[0]);
          // self.form.validEndTime = parseTime(self.form.effectivedate[1]).getTime();
          self.form.effectiveStartTime = this.$moment(self.form.effectivedate[0]).unix().toString();
          self.form.validEndTime = this.$moment(self.form.effectivedate[1]).unix().toString();
          delete self.form.effectivedate;
          delete self.form.idNumber;
          delete self.form.sLocalPicturePath;
          delete self.form.tel;
          delete self.form.type;
          delete self.form.registrationTime;
          if (self.infoType) {
            self.form.method = 1;
          } else {
            self.form.method = 2;
          }

          self.dialogFormVisible = false;
          if (self.form.identityType != 3 && self.form.identityType != 4) {
            self.form.thirdpartyId = '';
          }
          console.log(334, this.form);
          addPerson(this.form)
            .then((res) => {
              this.singleLoading = false;
              if (self.form.method == 1) {
                this.$message.success("注册成功");
              } else {
                this.$message.success("提交成功");
              }
              this.dialogFormVisible = false;
              delete self.form.identityData;
              setTimeout(() => {
                this.doGetCommunityPersons();
              }, 100);
            })
            .catch((err) => {
            });
        } else {
          this.singleLoading = false;
        }
      });
    },
    getFile(rawFile) {
      const params = new FormData();
      // params.append("personId", this.personId);
      params.append("fileType", 0);
      params.append("fileData", rawFile.raw);
      if (rawFile.size / 1024 / 1024 > 1) {
        this.$message.error("最大不超过1m!");
        this.$refs['uploadImg'].clearFiles()
        // this.getPersonFace();
        return false;
      }
      fileUploadApi(params).then((res) => {
        let path = ''
        if (res) {
          console.log(1137, res.path);
          // this.getPersonFace();
          this.facePath = res.path
          this.$message.success("上传成功");
        }
      });
    },
    handleRemove(file, row) {
      this.getPersonFace();
      let self = this;
      let params = {
        // identityID: file.identityID ?? row.identityID,
        identityData: this.facePath
      };
      console.log(1211, file, row);
      this.facePath = '';
      this.form.identityData = '';
      delUploadPicApi(params).then((res) => {
        if (res) {
          this.$message.success("删除成功");
          this.getPersonFace();
        }
      })
      .catch((e) => {
        console.log(e);
        this.$message.warning("删除失败");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
  /deep/  .el-select-dropdown__wrap {
    height: 280px !important;
  }

  // .el-select-dropdown.el-popper {
  //   height: 280px;
  // }
</style>
